package com.ztjy.sys.controller;

import com.ztjy.bean.CType;
import com.ztjy.bean.City;
import com.ztjy.bean.Job;
import com.ztjy.purchase.biz.CTypeBiz;
import com.ztjy.sys.biz.AreaBiz;
import com.ztjy.sys.biz.JobBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 通用的控制器方法
 */
@Controller
public class PageController {
    @Autowired
    private JobBiz jobBiz;
    @Autowired
    private AreaBiz areaBiz;
    @Autowired
    private CTypeBiz tbiz;

    @RequestMapping("/{path}")
    public String hello(@PathVariable("path") String page) {
        return page;
    }

    @RequestMapping("/{path}/{path1}/{path2}")
    public String hello(@PathVariable("path") String page, @PathVariable("path1") String page1, @PathVariable("path2") String page2) {
        String path = page + "/" + page1 + "/" + page2;
        return path;
    }

    /**
     * 首页进入login.html
     *
     * @return
     */
    @RequestMapping("/")
    public String hello() {
        return "login";
    }

    // ajax 获取职位 通过部门id获取职位
    @RequestMapping("/ajaxJobs")
    @ResponseBody
    public List<Job> getJobs(Integer did) {
        Job job = new Job();
        job.setJobDeptId(did);//根据部门查询
        job.setJobState("1");//查询启用
        List<Job> allJobs = jobBiz.findAllJobs(job);
        return allJobs;
    }

    // ajax 获取城市  通过省份id获取所有城市
    @RequestMapping("/ajaxCity")
    @ResponseBody
    public List<City> getCity(Integer pid) {
        List<City> cities = areaBiz.findCitiesByPId(pid);
        return cities;
    }
    //根据商品类型的到品牌
    @RequestMapping("/ajaxType")
    @ResponseBody
    public List<CType> getType(Integer bid){
        List<CType> types = tbiz.findCTypesByBId(bid);
        return types;
    }
}
